﻿@using System.Text.Encodings.Web
@using System.Text.RegularExpressions
@using Masuit.MyBlogs.Core.Common
@using Masuit.MyBlogs.Core.Models.Entity
@using Masuit.MyBlogs.Core.Models.ViewModel
@using Masuit.Tools.Core.Net
@model Masuit.MyBlogs.Core.Models.Entity.PostHistoryVersion[]
@{
    ViewBag.Title = Model[0].Title + "版本对比";
    Layout = "~/Views/Shared/_Layout.cshtml";
    string[] colors = { "success", "info", "primary", "warning", "danger", "default", "primary" };
    List<Advertisement> ads = ViewBag.Ads;
}
<style>
    ins {
        background-color: #cfc;
        text-decoration: none;
    }

    del {
        color: #999;
        background-color: #FEC8C8;
    }
</style>
<link href="~/Assets/UEditor/third-party/SyntaxHighlighter/styles/shCore.css" rel="stylesheet" />
<div class="container-fluid">
    <ol class="cd-breadcrumb triangle">
        <li><a asp-controller="Home" asp-action="Index">首页</a></li>
        <li><a asp-controller="Home" asp-action="Post">文章列表</a></li>
        <li><a asp-controller="Post" asp-action="Details" asp-route-id="@Model[0].Id">@Model[0].Title</a></li>
        <li><a asp-controller="Post" asp-action="History" asp-route-id="@Model[0].Id">历史版本</a></li>
        <li class="current">
            <em>版本对比</em>
        </li>
    </ol>
    <div class="row history">
        <div class="col-md-6">
            <div class="wrapper-content article">
                <div class="ibox">
                    <div class="ibox-content animated fadeIn">
                        <main>
                            <section class="article-content">
                                <header class="page-header">
                                    <div class="text-center">
                                        <a>
                                            <h2 class="padding-bot10">
                                                @Model[1].Title
                                            </h2>
                                        </a>
                                    </div>
                                    <div class="row">
                                        <div class="col-sm-8">
                                            <div class="padding-bot10">
                                                <span class="label label-@colors[new Random().Next() % colors.Length]">@Model[1].Modifier</span>修改于<span class="text-success">@Model[1].ModifyDate.ToTimeZoneF(Context.Session.Get<string>(SessionKey.TimeZone))</span> | 原分类：<i class="icon-map-pin"></i><a asp-controller="Home" asp-action="Category" asp-route-id="@Model[1].CategoryId" class="label label-@colors[new Random().Next() % colors.Length]">@Model[1].Category.Name</a>
                                                @if (Model[1].Seminar.Any())
                                                {
                                                    <span> | 原所属专题：</span>
                                                    var seminars = Model[1].Seminar;
                                                    foreach (var s in seminars)
                                                    {
                                                        <a asp-controller="Seminar" asp-action="Index" asp-route-id="@s.Id" class="label label-@colors[new Random().Next() % colors.Length]">@s.Title</a><text> </text>
                                                    }
                                                }
                                            </div>
                                        </div>
                                        @{
                                            if (!string.IsNullOrEmpty(Model[1].Label))
                                            {
                                                <div class="pull-right margin-right20">
                                                    <div>
                                                        @foreach (string s in Model[1].Label.Split(',', '，', ' '))
                                                        {
                                                            if (!string.IsNullOrEmpty(s))
                                                            {
                                                                <a asp-controller="Home" asp-action="Tag" asp-route-tag="@s">
                                                                    <span class="label label-@colors[new Random().Next() % colors.Length]">@s</span>
                                                                </a>
                                                            }
                                                        }
                                                    </div>
                                                </div>
                                            }
                                        }
                                    </div>
                                </header>
                                <article class="article" id="article">
                                    @if(!ViewBag.DisableCopy||Context.Request.IsRobot()) {
                                        @Html.Raw(await Model[1].Content.ReplaceImgAttribute(Model[1].Title))
                                    }
                                    else {
                                        @Html.Raw(Regex.Replace(await Model[1].Content.ReplaceImgAttribute(Model[1].Title), @"[\u4e00-\u9fa5]", m => HtmlEncoder.Default.Encode(m.Value)))
                                    }
                                    @Html.Raw(await Model[1].Content.ReplaceImgAttribute(Model[0].Title))
                                </article>
                            </section>
                            <hr class="margin-top10 marginbot10" />
                            @if (ads.Any())
                            {
                                await Html.RenderPartialAsync("_ArticleListAdvertisement", ads[0]);
                            }
                        </main>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-md-6">
            <div class="wrapper-content article">
                <div class="ibox">
                    <div class="ibox-content animated fadeIn">
                        <main>
                            <section class="article-content">
                                <header class="page-header">
                                    <div class="text-center">
                                        <a>
                                            <h2 class="padding-bot10">
                                                @Model[2].Title
                                            </h2>
                                        </a>
                                    </div>
                                    <div class="row">
                                        <div class="col-sm-8">
                                            <div class="padding-bot10">
                                                <span class="label label-@colors[new Random().Next() % colors.Length]">@Model[2].Modifier</span>修改于<span class="text-success">@Model[2].ModifyDate.ToTimeZoneF(Context.Session.Get<string>(SessionKey.TimeZone))</span> | 原分类：<i class="icon-map-pin"></i><a asp-controller="Home" asp-action="Category" asp-route-id="@Model[2].CategoryId" class="label label-@colors[new Random().Next() % colors.Length]">@Model[2].Category.Name</a>
                                                @if (Model[2].Seminar.Any())
                                                {
                                                    <span> | 原所属专题：</span>
                                                    var seminars = Model[2].Seminar;
                                                    foreach (var s in seminars)
                                                    {
                                                        <a asp-controller="Seminar" asp-action="Index" asp-route-id="@s.Id" class="label label-@colors[new Random().Next() % colors.Length]">@s.Title</a><text> </text>
                                                    }
                                                }
                                            </div>
                                        </div>
                                        @{
                                            if (!string.IsNullOrEmpty(Model[2].Label))
                                            {
                                                <div class="pull-right margin-right20">
                                                    <div>
                                                        @foreach (string s in Model[2].Label.Split(',', '，', ' '))
                                                        {
                                                            if (!string.IsNullOrEmpty(s))
                                                            {
                                                                <a asp-controller="Home" asp-action="Tag" asp-route-tag="@s">
                                                                    <span class="label label-@colors[new Random().Next() % colors.Length]">@s</span>
                                                                </a>
                                                            }
                                                        }
                                                    </div>
                                                </div>
                                            }
                                        }
                                    </div>
                                </header>
                                <article class="article" id="article">
                                    @if(!ViewBag.DisableCopy||Context.Request.IsRobot()) {
                                        @Html.Raw(await Model[2].Content.ReplaceImgAttribute(Model[2].Title))
                                    }
                                    else {
                                        @Html.Raw(Regex.Replace(await Model[2].Content.ReplaceImgAttribute(Model[2].Title), @"[\u4e00-\u9fa5]", m => HtmlEncoder.Default.Encode(m.Value)))
                                    }
                                </article>
                            </section>
                            <hr class="margin-top10 marginbot10" />
                            @if (ads.Count > 1)
                            {
                                await Html.RenderPartialAsync("_ArticleListAdvertisement", ads[1]);
                            }
                        </main>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div id="cyReward" role="cylabs" data-use="reward"></div>
</div>
<script src="~/Assets/UEditor/third-party/SyntaxHighlighter/scripts/shCore.js"></script>
<script src="~/Assets/UEditor/third-party/SyntaxHighlighter/scripts/bundle.min.js"></script>
<script>
    $(function () {
        SyntaxHighlighter.all();
        SyntaxHighlighter.defaults['toolbar'] = false;
    });
    @if(ViewBag.DisableCopy) {
        <text>
    GlobalCopyrightProtect();
        </text>
    }
</script>